package com.gitee.cirnochat.chat.consumer;


import com.gitee.cirnochat.websocket.model.dto.WebSocketUserMessage;
import com.gitee.cirnochat.websocket.service.WebSocketService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import static com.gitee.cirnochat.common.constant.MQConstant.CHAT_QUEUE_NAME;
import static com.gitee.cirnochat.common.constant.MQConstant.MESSAGE_EXCHANGE;
import static com.gitee.cirnochat.common.constant.MQKey.CHAT_MESSAGE_SEND_ROUTING_KEY;

@Slf4j
@Component
@RequiredArgsConstructor
public class MessageConsumer {
    private final WebSocketService webSocketService;

    /**
     * 处理聊天消息
     * @param webSocketUserMessage 聊天消息内容
     */
    public void handleMessage(WebSocketUserMessage webSocketUserMessage) {
        webSocketService.sendMessageToUser(webSocketUserMessage);
    }

    @RabbitListener(bindings = @QueueBinding(
            key = {CHAT_MESSAGE_SEND_ROUTING_KEY},
            value = @Queue(CHAT_QUEUE_NAME),
            exchange = @Exchange(name = MESSAGE_EXCHANGE, type = ExchangeTypes.DIRECT)))
    public void handleMessageSend() {

    }
}
